// hyb_yl/mysubpages/pages/docorder/docorder.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabitem: ['全部','待接诊', '咨询中', '已结束','已退回'],
    tabitems: ['全部','待接诊', '咨询中', '已完成','已取消'],
    docindex: 0,
    page:"0",
    list:[],
    index:0,
    ifpay: 1,

  },
  doctabs:function(e){
    const index = e.currentTarget.dataset.dex;
    var that = this
    var zid = that.data.zid
    var key_words = that.data.key_words
    console.log(key_words)
    var id = that.data.id
    that.setData({
      docindex:index,
    })
    if(key_words == 'shuhoukangfu')
    {
      that.setData({
        list:[],
        page:0
      })
      that.getOrder();
    }
  },
  // 康复指导
  kangfu:function(e){
    var that = this;
    var back_orser = e.currentTarget.dataset.back_orser;
    var j_id = e.currentTarget.dataset.j_id;
    var zid = e.currentTarget.dataset.zid;
    var is_zd = e.currentTarget.dataset.is_zd;
    wx.navigateTo({
      url: '/hyb_yl/krecovery/pages/guide/guide?back_orser='+back_orser+'&j_id='+j_id+'&zid='+zid+'&is_zd='+is_zd,
    })
  },
  doctab: function (e) {
    const index = e.currentTarget.dataset.dex;
    var that = this
    var zid = that.data.zid
    var key_words = that.data.key_words
    console.log(key_words)
    var id = that.data.id
    if(key_words == 'shuhoukangfu')
    {
      that.setData({
        list:[],
        page:0
      })
      that.getOrder();
    }
    if (key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getbglistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: index
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    if (key_words == 'yuanchengkaifang') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getcflistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: index
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    if (key_words == 'sirenyisheng') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getqylistser',
        data: {
          goods_id: zid,
          cerated_type: 7
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    if (key_words == 'yuanchengguahao') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getghlistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: index
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    this.setData({
      docindex: (index - 1)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    this.setData({
      bg_color: bgc
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    var state = options.state;
    var titlme = options.titlme
    var id = options.id
    var key_words = options.key_words
    var zid = options.zid
    var ifpay = that.data.ifpay
    
    console.log(state != '' || state != undefined)
    if(state != '' && state != undefined)
    {
      that.setData({
        docindex: state,
      })
    }
    console.log(that.data.docindex);
    that.setData({
      
      ftitle: titlme,
      id: id,
      key_words: key_words,
      zid: zid
    })
    wx.setNavigationBarTitle({
      title: titlme + '订单'
    })
    if(key_words == 'shuhoukangfu')
    {
      that.getOrder();
    }
    //处方订单
    if (key_words == 'yuanchengkaifang') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getcflistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: ifpay
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    //私人医生
    //
    if (key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getbglistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: 1
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
    if (key_words == 'yuanchengguahao') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getghlistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: 1
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
  },
  getOrder: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/green.shuhou_lists",
      data: {
        zid: that.data.zid,
        page: that.data.page,
        status: that.data.docindex
      },
      success: function (res) {
        var page = that.data.page + 1;
        that.setData({
          page: page,
          list: that.data.list.concat(res.data)
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    var zid = that.data.zid
    var key_words = that.data.key_words
    var id = that.data.id
    var ifpay = that.data.ifpay
    if (key_words == 'yuanchengkaifang') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.getcflistser',
        data: {
          zid: zid,
          key_words: key_words,
          id: id,
          ifpay: ifpay
        },
        success: function (res) {
          console.log(res)
          that.setData({
            list: res.data
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var key_words = that.data.key_words;
    if(key_words == 'shuhoukangfu')
    {
      that.getOrder();
    }
  },
  // 术后康复接诊
  jiezhen:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var back_orser = e.currentTarget.dataset.back_orser;
    var key_words = that.data.key_words;
    if(key_words == 'shuhoukangfu')
    {
      app.util.request({
        'url':"entry/wxapp/green.shuhou_jiedan",
        data:{
          back_orser:back_orser,
        },
        success:function(res){
          that.setData({
            page:0,
            list:[],
  
          })
          app.util.request({
            'url':"entry/wxapp/zhuanjia.shjzmsgdh",
            data:{
              id:id
            },
            success:function(res){
              
            }
          })
          that.getOrder();
        }
      })
    }else{
      app.util.request({
        'url':"entry/wxapp/green.order_accept",
        data:{
          back_orser:back_orser,
          id:id,
          did:that.data.did,
          zid:that.data.zid,
        },
        success:function(res){
          that.setData({
            page:0,
            list:[],
  
          })
          app.util.request({
            'url':"entry/wxapp/zhuanjia.shjzmsgdh",
            data:{
              id:id
            },
            success:function(res){
              
            }
          })
          that.getOrder();
        }
      })
    }
    
  },
  toorder:function(e){
    wx.navigateTo({
      url: '/hyb_yl/krecovery/pages/postoperative_ordercont/postoperative_ordercont?back_orser='+e.currentTarget.dataset.back_orser+'&doc=1',
    })
  },
  getchar(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = that.data.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var j_id = e.currentTarget.dataset.j_id
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yishengkaifang/yishengkaifang?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&zid=' + zid + '&j_id=' + j_id,
    })
  },
  entrec(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var useropenid = e.currentTarget.dataset.useropenid
    var back_orser = e.currentTarget.dataset.back_orser
    var j_id = e.currentTarget.dataset.j_id
    wx.showModal({
      title: '是否确认接诊',
      success: function (res) {
        //
        if (res.confirm) {
          //更新处方订单状态
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.updatecforder',
            data: {
              back_orser: back_orser
            },
            success(res) {
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.kfjzmsgdh',
                data: {
                  id: id,
                },
                success: function (res) {
                  console.log(res)
                }
              })
              wx.navigateTo({
                url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiahuida/zhuanjiahuida?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&openid=' + useropenid + '&back_orser=' + back_orser+'&j_id='+j_id,
              })
            }
          })

        }
      }
    })

  },

  entrec2(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var useropenid = e.currentTarget.dataset.useropenid
    var back_orser = e.currentTarget.dataset.back_orser
    var j_id = e.currentTarget.dataset.j_id
    wx.showModal({
      title: '是否确认接诊',
      success: function (res) {
        //
        if (res.confirm) {
          //更新挂号订单状态
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.updateghorder',
            data: {
              back_orser: back_orser
            },
            success(res) {
              app.util.request({
                'url':"entry/wxapp/zhuanjia.ghjzmsgdh",
                data:{
                  id:id
                },
                success:function(res){

                }
              })
              console.log(res)
              wx.navigateTo({
                url: '/hyb_yl/zhuanjiasubpages/pages/postoperative_ordercont/postoperative_ordercont?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&openid=' + useropenid + '&back_orser=' + back_orser+'&j_id='+j_id,
              })
            }
          })

        }
      }
    })
    
  },
  entrec3(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var useropenid = e.currentTarget.dataset.useropenid
    var back_orser = e.currentTarget.dataset.back_orser
    var j_id = e.currentTarget.dataset.j_id
    wx.showModal({
      title: '是否确认接诊',
      success: function (res) {
        //
        if (res.confirm) {
          //更新挂号订单状态
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.updatesskyorder',
            data: {
              back_orser: back_orser
            },
            success(res) {
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.dianhuamsgdh',
                data: {
                  id: id,
                },
                success: function (res) {
                  console.log(res)
                }
              })
              wx.navigateTo({
                url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiahuida/zhuanjiahuida?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&openid=' + useropenid + '&back_orser=' + back_orser+'&j_id='+j_id,
              })
            }
          })

        }
      }
    })
  },
  reply(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid
    var typedate = e.currentTarget.dataset.typedate
    var key_words = that.data.key_words
    var useropenid = e.currentTarget.dataset.useropenid
    var back_orser = e.currentTarget.dataset.back_orser
    var j_id = e.currentTarget.dataset.j_id
    var ifpay = e.currentTarget.dataset.ifpay
    var money = e.currentTarget.dataset.money
    var docindex = that.data.docindex
    if(key_words == 'yuanchengguahao')
    {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/postoperative_ordercont/postoperative_ordercont?txt=yes&doc=1&zid=' + zid + '&back_orser=' + back_orser + '&key_words=yuanchengguahao' + '&j_id=' + j_id + '&ifpay=' + ifpay + '&money=' + money + '&id=' + id,
      })
    }else{
      
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiahuida/zhuanjiahuida?txt=yes&doc=1&zid=' + zid + '&back_orser=' + back_orser + '&key_words='+key_words + '&j_id=' + j_id + '&ifpay=' + ifpay + '&money=' + money + '&id=' + id,
      })
    }
    
  },
  reply1(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var zid = e.currentTarget.dataset.zid
    var money = e.currentTarget.dataset.money
    var orders = e.currentTarget.dataset.orders
    var ifpay = e.currentTarget.dataset.ifpay
    var j_id = e.currentTarget.dataset.j_id
    if(key_words == 'yuanchengguahao')
    {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/postoperative_ordercont/postoperative_ordercont?txt=yes&doc=1&zid=' + zid + '&back_orser=' + back_orser + '&key_words=yuanchengguahao' + '&j_id=' + j_id + '&ifpay=' + ifpay + '&money=' + money + '&id=' + id,
      })
    }else{
      
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/zhuanjiahuida/zhuanjiahuida?txt=yes&doc=1&zid=' + zid + '&back_orser=' + back_orser + '&key_words='+key_words + '&j_id=' + j_id + '&ifpay=' + ifpay + '&money=' + money + '&id=' + id,
      })
    }
  }
})